#include <unistd.h>
#include <sys/ioctl.h>

#include "r_socket_common.h"

namespace eniac
{
    uint64_t r_socket_common::get_readable_bytes_length(int32_t socket_fd)
    {
        if (-1 == socket_fd)
        {
            return 0;
        }

        int readable_bytes_length = 0;
        if (ioctl(socket_fd, FIONREAD, &readable_bytes_length) < 0)
        {
            return 0;
        }

        return readable_bytes_length;
    }
}